package com.yuan.yblog.portal.config;

import com.alibaba.otter.canal.client.CanalConnector;
import com.alibaba.otter.canal.client.CanalConnectors;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetSocketAddress;

/**
 * @author hepeiyuan on 2024/5/30 22:24
 * @description canal配置类
 */
@Configuration
public class CanalConfig {

    @Value("${canal.hostname}")
    public String hostname;

    @Value("${canal.port}")
    public int port;

    @Value("${canal.destination}")
    public String destination;

    @Value("${canal.username}")
    public String username;

    @Value("${canal.password}")
    public String password;

    /**
     * canal服务器连接器
     * @return CanalConnector
     */
    @Bean
    public CanalConnector canalConnector () {
        return CanalConnectors.newSingleConnector(
                new InetSocketAddress(hostname, port),
                destination,
                username,
                password);
    }
}
